<template>
  <div>
    <div class="type-container-p">
      <div class="type-desc-container">
        <div class="type-title">
          分类
        </div>
        <div class="type-count">
          ({{ typeList.length }}个)
        </div>
      </div>

      <div class="type-content">
        <ul class="type-container">
          <router-link v-for="item in typeList" :key="item.typeId" :to="{path:'/blogList',query:{type:item.typeId}}" class="type-item">
            {{ item.typeName }} ({{ item.typeBlogCount }})
          </router-link>
        </ul>
      </div>
      <div class="tag-desc-container">
        <div class="tag-desc-top">
          <div class="tag-title">
            标签
          </div>
          <div class="tag-count">
            ({{ tagList.length }}个)
          </div>
        </div>
        <div class="tags-containers">
          <a-tag v-for="(item2,index) in tagList" :key="index" class="tag-item" :color="item2.tagColor" @click="getListBlogByTagId(item2.tagId)">{{ item2.tagName }} [{{ item2.tagBlogCount||0 }}]</a-tag>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import typeApi from '@/api/type'
import tagApi from '../../api/tag'
export default {
  name: 'Index',
  data() {
    return {
      typeList: [],
      tagList: [],
      page: {
        currentPage: 0, // 当前页
        pageSize: 5, // 页面大小
        pageTotal: 0, // 总页数
        countTotal: 0, // 总条数
        sortColumn: '', // 排序字段
        sortMethod: 'asc', // 排序方法
        list: [], // 数据
        params: {} // 条件查询参数
      }
    }
  },
  created() {
    this.getTypeList()
    this.getEnabledTags()
  },
  methods: {
    getListBlogByTagId(tagId) {
      this.$router.push({ path: `/blogList`, query: { tagId: tagId }})
    },
    getTypeList() {
      typeApi.getList().then(res => {
        if (res.code === 200) {
          this.typeList = res.data
        } else {
          this.$message.error(res.msg)
        }
      })
    },
    getEnabledTags() {
      tagApi.getEnabledTags().then(res => {
        if (res.code === 200) {
          this.tagList = res.data
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
.type-container-p{
  display: flex;
  flex-flow: column nowrap;
  padding: 15px;
  background-color: #ffffff;
  .type-desc-container{
    display: flex;
    flex-flow: row nowrap;
    align-items: center;
    .type-title{
      font-size: 24px;
      font-weight: bold;
      color: #333333;
      text-align: left;
    }
    .type-count{
      margin-left: 10px;
      text-align: center;
      font-size: 18px;
      color: #a2a2a2;
    }
  }
  .tag-desc-container{
    display: flex;
    flex-flow: column nowrap;
    margin-top: 95px;
    align-items: center;
    justify-content: flex-start;
    .tag-desc-top{
      width: 100%;
      display: flex;
      flex-flow: row nowrap;
      align-items: center;
      .tag-title{
        font-size: 24px;
        font-weight: bold;
        color: #333333;
        text-align: left;
      }
      .tag-count{
        margin-left: 10px;
        text-align: center;
        font-size: 18px;
        color: #a2a2a2;
      }
    }
    .tags-containers{
      width: 100%;
      display: flex;
      flex-flow: row wrap;
      justify-content: flex-start;
      align-items: center;
      padding-bottom: 150px;
      .tag-item{
        margin: 15px 15px 15px 0;
      }
    }
  }
  .type-content{
    display: flex;
    flex-flow: row nowrap;
    justify-content: center;
    padding-top: 20px;
    .type-container{
      display: flex;
      flex-flow: row wrap;
      justify-content: flex-start;
      padding: 0;
      .type-item{
        margin: 5px 20px 25px 0;
        line-height: 30px;
        font-size: 18px;
        text-align: center;
        list-style: none !important;
        border-bottom: 2px dashed #1890ff;
        box-sizing: border-box;
        &:hover{
          color: red;
          border-bottom: 2px solid red;
        }
      }
    }

  }

}
</style>
